w int main() {
•
•
•
•
•
w
w
w
w
w
w
w
w
w
w}
int *pointer1 = new int;
int *pointer2 = new int;
new() and delete()
Example
cout << 'the value of pointer1 is ‘ << *pointer1;
The value of pointer1 is deleted!!!!!!!!!!!!!!!!! Pointer does not point to any data!!!!
cout << “pointer1: “ << *pointer1
<< “; pointer2: “ << *pointer2;
OUTPUT:
pointer1: 10; pointer2: 25
3
*pointer1 = 3;
pointer1: 3; pointer2: 3
cout << “pointer1: “ << *pointer1
<< “; pointer2: “ << *pointer2;
10
25
*pointer1 = 10;
*pointer2 = 25;
delete pointer1;
6FA70
pointer1 = pointer2;
delete pointer2;
points
access denied